<!DOCTYPE html>
<html lang="en">
<head>
    <title>首件检验登记-精工云MES系统移动端</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link href="/JG/Content/jquery/weui/style/weui.min.css" rel="stylesheet" />
    <link href="/JG/Content/jquery/jquery-weui/css/jquery-weui.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="/JG/Content/css/bootstrap.min.css">
    <link href="/JG/Content/css/Global.css" rel="stylesheet" />
    <link href="/JG/Content/jquery/jquery-weui/css/icon.css" rel="stylesheet" />
    <link rel="stylesheet" href="/JG/Content/css/MobileFirstItemInspection.css?v=1">

    <script src="/JG/Content/jquery/jquery-3.2.1.min.js"></script>
    <script src="/JG/Content/LocalConfigs.js"></script>
    <script src="/JG/Content/LocalUserInfo.js"></script>
    <script src="/JG/Content/Utils.js?v=1"></script>

    <style type="text/css">
        /*.menuTree{*/
            /*margin-left:-30px;*/
        /*}*/
        /*.menuTree div{*/
            /*padding-left:30px;*/
        /*}*/

        /*.menuTree span:hover{*/
            /*background-color:#e6e6e6;*/
            /*color:#cf0404;*/
        /*}*/

        /*.menuTree a:hover{*/
            /*color:#06F;*/
        /*}*/
        /*.btn{*/
            /*height:30px;*/
            /*margin-top:10px;*/
            /*border-bottom:1px solid #CCC;*/
        /*}*/
    </style>
</head>
<body>
    <div id="ContentContainer">
        <header id="Header" class="header">
            <div class="empty">
                <span id="stations"></span>
            </div>
            <div class="weui-flex">
                <div class="weui-flex__item" style="position:absolute;">
                <span style="font-size:16px;padding-left: 10px;" class="icon icon-109 f-white" onclick="javascript:location.href='/JG/Quality/MobileFirstCheckout.html'">
                    返回
                </span>
                </div>
                <div class="weui-flex__item" style="text-align: center;">首件检验登录</div>
                <div class="weui-flex__item" style="position:absolute;right:10px;">
                    <span @click="SaveBtn"><img src="/JG/Content/images/save.png" alt="" style="width:25px;"></span>
                </div>
            </div>
        </header>
        <!--解决浮动空内容div-->
        <div class="empty_div"></div>
        <!--主体部分-->
        <div id="MainPage" v-cloak>
            <div class="vessel" style="background-color: #FFFFFF">
                <div class="vessel_top">
                    <ul class="list-group">
                        <li class="list-group-item">
                            <div>
                                <span class="list-group-item-heading">生产线</span>
                                <select class="form-control" v-model="FormData.NowProductionLineCode" v-on:change="ChooseProductionLine">
                                    <option v-for="(item,index) in ProLineData" v-bind:value="item.CXSJ_CXBM">{{item.CXSJ_CXMC}}</option>
                                </select>
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div>
                                <span class="list-group-item-heading">送检人</span>
                                <input v-model="FormData.InspectName" class="div_input div_input1" type="text" placeholder="请输入送检人姓名">
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div>
                                <span class="list-group-item-heading">检验人</span>
                                <input v-model="LoginUser" readonly="readonly" class="div_span" type="text">
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div>
                                <span class="list-group-item-heading">任务单号</span>
                                <input v-model="FormData.TaskCode" class="popup_input" type="text" readonly="readonly">
                                <button type="button" class="choice"
                                        style="width:42px;line-height: 25px;font-size: 14px;color: #FFFFFF;background-color: #4BA250;border:none;border-radius: 2px">选择</button>
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div>
                                <span class="list-group-item-heading">订单号</span>
                                <input v-model="FormData.OrderCode" disabled="value" class="div_span" type="text">
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div>
                                <span class="list-group-item-heading">产品编号</span>
                                <input v-model="FormData.InvCode" readonly="readonly" class="div_span" type="text">
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div>
                                <span class="list-group-item-heading">产品名称</span>
                                <input v-model="FormData.InvName" class="popup_input" type="text" readonly="readonly">
                                <!--<button type="button" class="choice"-->
                                <!--style="width:42px;line-height: 25px;font-size: 14px;color: #FFFFFF;background-color: #4BA250;border:none;border-radius: 2px">选择</button>-->
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div>
                                <span class="list-group-item-heading">检验方案</span>
                                <select  class="form-control select_val" v-on:change="CheckoutProjectClick(this)" v-model="FormData.MasterID">
                                    <option v-for="(item,index) in CheckoutProject" v-bind:value="item.JGMES_ZLGL_CPJYBZ_ID">{{item.CPJYBZ_BZMC}}</option>
                                </select>
                            </div>
                        </li>
                        <li class="list-group-item">
                            <!--图片点击放大弹窗部分-->
                            <div class="weui-gallery" id="gallery">
                                <!--预览图片容器-->
                                <div class="weui-gallery__img" id="galleryImg"></div>
                                <!--图片删除按钮-->
                                <div class="weui-gallery__opr">
                                    <a href="javascript:" class="weui-gallery__del" style="display: inline-block;width:100px;text-align: left">
                                        <i class="weui-icon-delete weui-icon_gallery-delete">删除</i>
                                    </a>
                                    <a href="javascript:" class="weui-back" id="weui-back" style="display: inline-block;width:100px;text-align: right">
                                        <span class="text-back" style="font-size: 1.3em;color:#FFFFFF">返回</span>
                                    </a>
                                </div>
                            </div>

                            <!--上传图片按钮部分和显示图片部分-->
                            <div class="weui-cells weui-cells_form">
                                <div class="weui-cell">
                                    <div class="weui-cell__bd">
                                        <div class="weui-uploader">
                                            <div class="weui-uploader__hd">
                                                <p class="weui-uploader__title">图片上传(最多上传5张)</p>
                                            </div>
                                            <div class="weui-uploader__bd">
                                                <!--上传图片容器-->
                                                <ul class="weui-uploader__files" id="uploaderFiles"></ul>
                                                <!--上传图片按钮-->
                                                <!--<div class="weui-uploader__input-box">-->
                                                <!--<input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple=""-->
                                                <!--v-on:change="UploadingImg">-->
                                                <!--</div>-->
                                                <div class="weui-uploader__input-box" v-if="CurrImgNum<MaxImgNum">
                                                    <input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple=""
                                                           v-on:change="UploadingImg">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div>
                                <i v-on:click="GoCheckoutProject" style="width:10px;height:20px;display: inline-block;position: absolute;z-index:10;top:22.5px;right:7px;">
                                    <img src="/JG/Content/images/xiaojiantou.png" alt="" style="width:100%;">
                                </i>
                                <input type="text" placeholder="检验项目明细" style="position: relative;width:100%;line-height: 45px;border: none;outline-style: none">
                            </div>
                        </li>
                        <li class="list-group-item">
                            <div>
                                <span>检验结果</span>
                                <span class="choice_btn" style="margin-left: 89px;">
                                <input type="radio" name="judge" value="合格">合格
                                <input type="radio" name="judge" value="不合格">不合格
                            </span>
                            </div>
                        </li>
                    </ul>
                </div>

                <!--保存按钮部分-->
                <!--<div class="save_btn">-->
                <!--<button type="button" style="background-color: #4EA057;" v-on:click="SaveBtn">保存</button>-->
                <!--</div>-->
            </div>

            <!--任务列表弹窗选项部分-->
            <div tabindex="-1" class="modal fade in" id="myModal" role="dialog" aria-hidden="true" aria-labelledby="myModalLabel">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <!--头部-->
                        <div class="modal-header">
                            <div>
                                <button class="close" aria-hidden="true" type="button" data-dismiss="modal">×</button>
                                <h4 class="modal-title" id="myModalLabel">生产任务列表</h4>
                            </div>
                            <!--搜索框部分-->
                            <div class="task_btn row">
                                <div class="search_list col-lg-12 col-md-12 col-sm-12" style="text-align: left">
                                    <div class="search_item">
                                        <span>单据信息</span>
                                        <input v-model="FormData.ProTaskCode" id="ProTaskCode" type="text" placeholder="工单号/任务单号">
                                    </div>
                                    <div class="search_item">
                                        <span>产品信息</span>
                                        <input v-model="FormData.KeyWord" id="KeyWord" type="text" placeholder="产品编号/产品名称/型号">
                                    </div>
                                    <div class="shut_btn">
                                        <button class="btn btn-success" v-on:click="SearchLine()">搜索</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--内容部分-->
                        <div class="modal-body" id="tanchu" style="overflow-x: auto;overflow-y: auto;">
                            <div class="info">
                                <div class="list-group div_group" v-for="(item,index) in TaskCodeGat">
                                    <div class="list-group-item">
                                        <label class="list-group-item-heading">订单号码</label>
                                        <span class="list-group-item-text"> {{item.OrderCode}}</span>
                                    </div>
                                    <div class="list-group-item">
                                        <label class="list-group-item-heading">任务单号</label>
                                        <span class="list-group-item-text"> {{item.TaskCode }}</span>
                                    </div>
                                    <div class="list-group-item">
                                        <label class="list-group-item-heading">产品编码</label>
                                        <span class="list-group-item-text"> {{item.InvCode }}</span>
                                    </div>
                                    <div class="list-group-item">
                                        <label class="list-group-item-heading">产品名称</label>
                                        <span class="list-group-item-text"> {{item.InvName }}</span>
                                    </div>
                                    <!--<div class="list-group-item">-->
                                    <!--<label class="list-group-item-heading">检验方案</label>-->
                                    <!--<span class="list-group-item-text">{{item.SCRW_CPGG }}</span>-->
                                    <!--</div>-->
                                    <div class="list-group-item sub_btn">
                                        <input class="radio_input" type="button" name="inputs" value="选择" @click="SubData(item)" />
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

<script src="/JG/Content/jquery/jquery-weui/js/jquery-weui.min.js"></script>
<script src="/JG/Content/bootstrap.min.js"></script>
<script src="/JG/Content/vue-v2.34.js"></script>
<script src="/JG/Content/Common.js"></script>

<script type="text/javascript">
    //body赋值滚动条
    window.onload = function () {
        var BodyWidth = $(window).width();
        var BodyHeight = $(window).height();
        //任务列表弹窗
        var ModalBodyHeight = BodyHeight-165;
        $("#tanchu").height(ModalBodyHeight);
    }


    //上传图片部分的效果功能
    var SelImgIndex; //第几张图片
    $(function () {
        $gallery = $("#gallery");            //弹窗图片最外层div
        $galleryImg = $("#galleryImg");      //获取弹窗图片容器ID
        $uploaderInput = $("#uploaderInput");     //上传图片按钮
        $uploaderFiles = $("#uploaderFiles");     //上传的图片容器
        $gallery__del = $(".weui-gallery__del");     //获取弹窗图片删除按钮
        $galleryBack=$("#weui-back");       //获取弹窗图片返回按钮

        //点击图片放大效果
        $uploaderFiles.on("click", "li", function () {
            SelImgIndex = $(this).index();      //获取点击当前元素的下标
            $galleryImg.attr("style", this.getAttribute("style"));     //getAttribute() 方法通过名称获取属性的值。获取当前点击元素的style属性让后改为display：block
            $gallery.fadeIn(100);      //显示弹窗图片
        });

        //点击弹窗图片返回
        $galleryBack.on("click", function () {
            // $uploaderFiles.find("li");
            $gallery.fadeOut(100);      //隐藏图片
        });
        // $gallery.on("click", function () {
        //     $uploaderFiles.find("li")
        //     $gallery.fadeOut(100);
        // });

        //删除图片效果
        $gallery__del.click(function () { //这部分刚才放错地方了，放到$(function(){})外面去了
            event.stopPropagation();     //制止冒泡事件
            $.confirm("确认要删除该图片吗？", "删除提示", function () {
                // $uploaderFiles.find("li").eq(SelImgIndex).remove();
                // $gallery.fadeOut(100);      //隐藏图片


                var li = $uploaderFiles.find("li").eq(SelImgIndex);
                if (vmPage.ImagePaths && vmPage.ImagePaths.length > 0) {
                    vmPage.ImagePaths.splice(SelImgIndex, 1);
                }
                li.remove();   //删除一张移除一个li标签
                var num = $('.weui-uploader__file').length;
                vmPage.CurrImgNum = num;
                $gallery.fadeOut(100);

            });
        });
    });


</script>
<script type="text/javascript">
    var vmPage = new Vue({
        el:"#ContentContainer",
        data:{
            //ProductionLineCode:"",   //当前用户登陆产线对应的产线编码编码
            LoginUser:LocalUserInfo.GetUserInfo().UserName,     //当前登陆用户
            curDate: "",   //当前时间的产线
            ImagePaths: [], //上传图片文件集合
            CurrImgNum:"",    //上传图片的数量,也就是li标签数量
            MaxImgNum:"5",     //限制图片张数
            FormData:{
                ProdLine:"",    //产线名称
                InspectName:"",    //送检人姓名
                ProductionDate:"" ,  //计划日期
                OrderCode :"",       //订单号,
                TaskCode :"",         //任务单号
                InvCode :"",         //产品编码
                InvName:"",        //产品名称
                CheckoutType:"",     //检验类型
                CheckoutTypeCode:"",      //检验方案类型编码
                ProTaskCode:"",     //用户输入的工单号/任务单号
                KeyWord:"",        //用户输入的产品编号/产品名称/型号
                NowProductionLineCode:"",         //当前用户选择的产线编码
                MasterID:"",     //主表主键ID
                CheckoutClassifyName:"",     //检验分类名称
                YesOrNotCheckout:"",     //是否选中的合格或不合格
                //TextValue:"",       //检验值
                //DisQualification:"不合格",
                //Qualification:"合格",
                // ImgID: "",
                // StudentImg: ""
            },
            ProLineData: [],   //产线集合
            TaskCodeGat: [],  //任务单号信息集合
            CheckoutProject:[],     //检验方案集合
            //InspectionList:[],      //检验项目表数据集合
            //YesOrNotCheckoutList:[],    //是否选中的合格或不合格集合
        },
        mounted:function(){
            var currSelf = this;
            currSelf.initData();  //初始化
            currSelf.ProdLineMethod();  //初始化
        },
        methods:{
            //初始化方法
            initData: function () {
                var currSelf = this;
                $.showLoading();
                $.ajax({
                    type: "post",
                    async: true,   //异步
                    url: LocalConfig.SrvPath + "/jgmes/jgmesBaseAction!getCxList.action",
                    data: {},
                    dataType: "json",
                    success: function (result) {
                        var retData = ReturnData(result);
                        //console.log(retData);
                        if (retData.IsSuccess) {
                            if (retData.Data && retData.Data.length > 0) {
                                currSelf.ProLineData = retData.Data;
                                currSelf.FormData.NowProductionLineCode = LocalUserInfo.GetUserInfo().ProductionLineCode;   //把用户登陆时绑定的产线编码赋值

                                //初始化任务单信息
                                if(currSelf.FormData.NowProductionLineCode){
                                    //任务单号接口
                                    $.ajax({
                                        type: "post",
                                        async: true,
                                        url: LocalConfig.SrvPath + "/jgmes/commonAction!getScrw.action",
                                        data: {
                                            "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                            "mac": LocalUserInfo.GetUserInfo().Mac,
                                            "cxCode": currSelf.FormData.NowProductionLineCode,      //当前用户选择的产线
                                            "curDate": currSelf.curDate,
                                        },
                                        dataType: "json",
                                        success: function (result) {
                                            var ret = ReturnData(result);
                                            if (ret.IsSuccess) {
                                                if (ret.Data.length > 0) {
                                                    //console.log(ret.Data);
                                                    currSelf.FormData.TaskCode=ret.Data[0].SCRW_RWDH;    //任务单号
                                                    currSelf.FormData.InvCode=ret.Data[0].SCRW_CPBH;    //产品编码
                                                    currSelf.FormData.OrderCode=ret.Data[0].SCRW_DDHM;    //订单号
                                                    currSelf.FormData.InvName=ret.Data[0].SCRW_NAME;    //产品名称
                                                    currSelf.FormData.WordCode=ret.Data[0].SCRW_GDHM   //工单号

                                                    //初始化检验方案信息
                                                   if(currSelf.FormData.InvCode){
                                                       //根据产品获取检验方案列表接口
                                                       $.ajax({
                                                           type: "post",
                                                           async: true,
                                                           cache: true,
                                                           url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandard.action",
                                                           data: {
                                                               "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                               "mac": LocalUserInfo.GetUserInfo().Mac,
                                                               "cpbm": currSelf.FormData.InvCode,      //产品编码
                                                               "jylx":"SJ",     //检验类型(固定值)
                                                           },
                                                           dataType: "json",
                                                           success: function (ret) {
                                                               var retData = ReturnData(ret);
                                                               if (retData.IsSuccess && retData.Data) {
                                                                   //console.log(retData.Data);
                                                                   currSelf.CheckoutProject = retData.Data;
                                                                   currSelf.FormData.MasterID=retData.Data[0].JGMES_ZLGL_CPJYBZ_ID;
                                                               } else if (!retData.Data){
                                                                   var showMsg = "此任务单没有绑定相关的检验方案!";
                                                                   $.toptip(showMsg, "warning");
                                                               }
                                                           },
                                                           error: function (xhr, status, errorThrown) {
                                                               console.error(errorThrown);
                                                           }
                                                       });
                                                   }

                                                }
                                            }else if(!ret.Data){
                                                var showMsg = "该生产产线没有任务信息!";
                                                // currSelf.SetOperateRecord(showMsg, false);
                                                $.toptip(showMsg, "warning");
                                            }
                                        },
                                        error: function (xhr, status, errorThrown) {
                                            console.error(errorThrown);
                                        }
                                    });
                                }
                            }
                        }else if(!retData.Data){
                            var showMsg = "未能找到产线信息";
                            $.toptip(showMsg, "warning");
                        }
                    },
                    error: function (xhr, status, errorThrow) {
                        // console.error(status);
                        $.toptip(status, "warning");
                    },
                    complete: function () {
                        $.hideLoading();
                    },
                });
            },

            //选择切换当前产线方法
            ChooseProductionLine:function(){
                var currSelf = this;
                $.each(currSelf.ProLineData, function (index, item) {
                    if (currSelf.FormData.NowProductionLineCode == item.CXSJ_CXBM) {
                        currSelf.FormData.NowProductionLineCode = item.CXSJ_CXBM;      //当前产线编码
                        currSelf.FormData.ProdLine = item.CXSJ_CXMC;
                        currSelf.SwitcherProductionLine();
                    }
                });
            },

            //另外选择产线时,页面数据重新赋值方法
            SwitcherProductionLine:function(){
                var currSelf = this;
                currSelf.FormData.InspectName="";    //清空送检人
                currSelf.TaskCodeGat=[];      //清空上一次产线任务单信息
                currSelf.CheckoutProject = [];     //清空之前请求的检验方案集合
                currSelf.FormData.MasterID = "";    //清空之前选产线绑定的检验方案所对应的ID

                //初始化任务单信息
                if(currSelf.FormData.NowProductionLineCode){
                    //任务单号接口
                    // $.showLoading();
                    $.ajax({
                        type: "post",
                        async: true,
                        url: LocalConfig.SrvPath + "/jgmes/commonAction!getScrw.action",
                        data: {
                            "userCode": LocalUserInfo.GetUserInfo().UserCode,
                            "mac": LocalUserInfo.GetUserInfo().Mac,
                            "cxCode": currSelf.FormData.NowProductionLineCode,      //当前用户选择的产线
                            "curDate": currSelf.curDate,
                        },
                        dataType: "json",
                        success: function (result) {
                            var ret = ReturnData(result);
                            if (ret.IsSuccess) {
                                if (ret.Data.length > 0) {
                                    //console.log(ret.Data);
                                    currSelf.FormData.TaskCode=ret.Data[0].SCRW_RWDH;    //任务单号
                                    currSelf.FormData.InvCode=ret.Data[0].SCRW_CPBH;    //产品编码
                                    currSelf.FormData.OrderCode=ret.Data[0].SCRW_DDHM;    //订单号
                                    currSelf.FormData.InvName=ret.Data[0].SCRW_NAME;    //产品名称
                                    currSelf.FormData.WordCode=ret.Data[0].SCRW_GDHM   //工单号


                                    //初始化检验方案信息
                                    if(currSelf.FormData.InvCode){
                                        //根据产品获取检验方案列表接口
                                        // $.showLoading();
                                        $.ajax({
                                            type: "post",
                                            async: true,
                                            cache: true,
                                            url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandard.action",
                                            data: {
                                                "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                "mac": LocalUserInfo.GetUserInfo().Mac,
                                                "cpbm": currSelf.FormData.InvCode,      //产品编码
                                                "jylx":"SJ",     //检验类型(固定值)
                                            },
                                            dataType: "json",
                                            success: function (ret) {
                                                var retData = ReturnData(ret);
                                                if (retData.IsSuccess && retData.Data) {
                                                    //console.log(retData.Data);
                                                    currSelf.CheckoutProject = retData.Data;
                                                   currSelf.FormData.MasterID=retData.Data[0].JGMES_ZLGL_CPJYBZ_ID;
                                                } else if (!retData.Data){
                                                    var showMsg = "此任务单没有绑定相关的检验方案!";
                                                    $.toptip(showMsg, "warning");
                                                }
                                            },
                                            error: function (xhr, status, errorThrown) {
                                                console.error(errorThrown);
                                            }
                                        });
                                    }

                                }
                            }else if(!ret.Data){
                                var showMsg = "该生产产线没有任务信息!";
                                // currSelf.SetOperateRecord(showMsg, false);
                                $.toptip(showMsg, "warning");
                            }
                        },
                        error: function (xhr, status, errorThrown) {
                            console.error(errorThrown);
                        }
                    });
                }
            },

            //获取当前产线任务单全部信息方法
            ProdLineMethod: function () {
                var currSelf = this;
                $(".popup_input,.choice").click(function () {
                    //清空原有加载数据
                    currSelf.TaskCodeGat = [];
                    //currSelf.j = "";   //清空之前选中当前下标的任务列表数据

                    $("#myModal").modal("show");
                    $.showLoading();
                    //任务单号接口
                    $.ajax({
                        type: "post",
                        async: true,
                        url: LocalConfig.SrvPath + "/jgmes/commonAction!getScrw.action",
                        data: {
                            "userCode": LocalUserInfo.GetUserInfo().UserCode,
                            "mac": LocalUserInfo.GetUserInfo().Mac,
                            "cxCode": currSelf.FormData.NowProductionLineCode,      //当前用户选择的产线
                            "curDate": currSelf.curDate,
                            // "zt": "RWZT01,RWZT02,RWZT04"
                        },
                        dataType: "json",
                        success: function (result) {
                            var ret = ReturnData(result);
                            //console.log(ret);
                            if (ret.IsSuccess) {
                                if (ret.Data.length > 0) {
                                    for (var i in ret.Data) {
                                        var item = ret.Data[i];
                                        currSelf.TaskCodeGat.push({
                                            TaskCode: item.SCRW_RWDH,    //任务单号
                                            InvCode: item.SCRW_CPBH,     //产品编号
                                            OrderCode: item.SCRW_DDHM,  //订单号
                                            InvName: item.SCRW_NAME,  //产品名称
                                            WordCode: item.SCRW_GDHM,  //工单号
                                            //BgsjCxbm: item.SCRW_CXBM,  //产线编码
                                        });
                                    }
                                }
                            }else if(!ret.Data){
                                var showMsg = "该生产产线没有任务信息!";
                                // currSelf.SetOperateRecord(showMsg, false);
                                $.toptip(showMsg, "warning");
                            }
                        },
                        error: function (xhr, status, errorThrown) {
                            // $.alert("任务单号请求失败!");
                            $.toptip(status, "error");
                        },
                        complete: function () {
                            $.hideLoading();
                        }
                    });
                });
            },

            //点击弹窗选择按钮方法
            SubData: function (val) {
                var currSelf = this;
                currSelf.CheckoutProject=[];    //清空之前选择的检验方案
                currSelf.FormData.MasterID = "";    //清空绑定第一个检验方案的ID

                $("#myModal").modal("hide");
                currSelf.FormData.TaskCode = val.TaskCode;
                currSelf.FormData.OrderCode = val.OrderCode;
                currSelf.FormData.InvCode = val.InvCode;
                currSelf.FormData.InvName = val.InvName;

                $.showLoading();
                //根据产品获取检验方案列表接口
                $.ajax({
                    type: "post",
                    async: true,
                    cache: true,
                    url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandard.action",
                    data: {
                        "userCode": LocalUserInfo.GetUserInfo().UserCode,
                        "mac": LocalUserInfo.GetUserInfo().Mac,
                        "cpbm": currSelf.FormData.InvCode,      //产品编码
                        "jylx":"SJ",     //检验类型(固定值)
                    },
                    dataType: "json",
                    success: function (ret) {
                        var retData = ReturnData(ret);
                        console.log(retData);
                        if (retData.IsSuccess && retData.Data) {
                            currSelf.CheckoutProject = retData.Data;
                            currSelf.FormData.MasterID=retData.Data[0].JGMES_ZLGL_CPJYBZ_ID;
                        } else if (!retData.Data){
                            var showMsg = "此任务单没有绑定相关的检验方案!";
                            $.toptip(showMsg, "warning");
                        }
                    },
                    error: function (xhr, status, errorThrown) {
                        // console.error(status);
                        $.toptip(status, "error");
                    },
                    complete: function () {
                        $.hideLoading();
                    }
                });
            },

            //获取当前选中检验方案方法
            CheckoutProjectClick: function () {
                var currSelf = this;
                //currSelf.CheckoutClassifyData=[];

                $.each(currSelf.CheckoutProject, function (index, item) {
                    if (currSelf.FormData.MasterID == item.JGMES_ZLGL_CPJYBZ_ID) {
                        currSelf.FormData.CheckoutTypeCode = item.CPJYBZ_DJH;      //检验类型编码
                        currSelf.FormData.MasterID = item.JGMES_ZLGL_CPJYBZ_ID;
                    }
                });
            },

            //点击任务列表弹窗搜索按钮方法
            SearchLine:function(){
                var currSelf = this;

                if(!currSelf.FormData.NowProductionLineCode){
                    // bootbox.alert("请先输入需要搜索的内容!");
                    $("#ProTaskCode").focus();  //点击搜索按钮时，搜索框获取聚焦
                    $("#KeyWord").focus();  //点击搜索按钮时，搜索框获取聚焦
                }else{
                    currSelf.TaskCodeGat=[];
                    $.showLoading();
                    //任务单号接口
                    $.ajax({
                        type: "post",
                        async: true,
                        url: LocalConfig.SrvPath + "/jgmes/commonAction!getScrw.action",
                        data: {
                            "userCode": LocalUserInfo.GetUserInfo().UserCode,
                            "mac": LocalUserInfo.GetUserInfo().Mac,
                            "cxCode": currSelf.FormData.NowProductionLineCode,   //产线编码
                            "curDate": currSelf.curDate,    //当前产线的时间
                            "noLike":currSelf.FormData.ProTaskCode,    //获取当前用户输入任务单号
                            "cpLike":currSelf.FormData.KeyWord,     //获取当前用户输入产品关键字
                        },
                        dataType: "json",
                        success: function (result) {
                            var ret = ReturnData(result);
                            //console.log(ret);
                            if (ret.IsSuccess) {
                                if (ret.Data.length > 0) {
                                    for (var i in ret.Data) {
                                        var item = ret.Data[i];
                                        currSelf.TaskCodeGat.push({
                                            TaskCode: item.SCRW_RWDH,    //任务单号
                                            InvCode: item.SCRW_CPBH,     //产品编号
                                            OrderCode: item.SCRW_DDHM,  //订单号
                                            InvName: item.SCRW_NAME,  //产品名称
                                            WordCode: item.SCRW_GDHM,  //工单号
                                            //BgsjCxbm: item.SCRW_CXBM,  //产线编码
                                        });
                                    }
                                }
                            }else if(!ret.Data){
                                var showMsg = "搜索的该生产产线没有任务信息!";
                                $.toptip(showMsg, "warning");
                            }
                        },
                        error: function (xhr, status, errorThrown) {
                            console.error(errorThrown);
                            $.toptip("请求相关生产任务信息失败!", "error");
                        },
                        complete: function () {
                            $.hideLoading();
                        }
                    });
                }
            },

            //图片上传功能方法
            UploadingImg:function(event){
                var currSelf = this;
                //console.log(event);
                var ImgFormat = ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'];    //规定图片格式四种
                // 1024KB，也就是 1MB
                var maxSize = 1024 * 1024;    //设置图片最大容量
                var maxWidth = 150;         //图片最大宽度
                var files = event.target.files;     //event对象中的target里面的files属性
                //console.log(files);

                // 如果没有选中文件，直接返回
                if (files.length === 0) {
                    return;
                }

                if (currSelf.CurrImgNum + files.length > currSelf.MaxImgNum) {
                    // $.toptip("最多只能上传"+ currSelf.MaxImgNum +"张图片","warning");
                    $.toast("最多只能上传"+ currSelf.MaxImgNum +"张图片", "forbidden");
                    $("#uploaderInput").val();
                    return;
                    // $.alert('最多只能上传' + currSelf.MaxImgNum + '张图片');
                }

                //循环已上传的图片
                for (var i = 0; i < files.length; i++) {
                    var file = files[i];
                    //console.log(file);
                    //FileReader主要用于将文件内容读入内存，通过一系列异步接口，可以在主线程中访问本地文件
                    var reader = new FileReader();

                    // 如果上传图片类型不在允许的类型范围内
                    if (ImgFormat.indexOf(file.type) === -1) {
                        $.toast('该类型不允许上传', "forbidden");
                        continue;
                    }

                    //html5 使用readAsDataURL生成的base64编码的图片是2进制流，其优点是减少http的请求
                    reader.readAsDataURL(file);    //异步读取文件内容，结果用data:url的字符串形式表示

                    //当读取操作成功完成时调用onload事件
                    reader.onload = function (e) {
                        var img = new Image();      //创建一个img对象，也就是img标签
                        img.src = e.target.result;    //获取当前上传

                        //当图像装载完毕时调用的onload事件句柄。
                        img.onload = function () {
                            var w = Math.min(maxWidth, img.width);    //Math.min返回给定数值中最小的数。如果任一参数不能转换为数值，则返回NaN
                            var h = img.height * (w / img.width);

                            //h5新特性，绘制图形
                            var canvas = document.createElement('canvas');
                            var ctx = canvas.getContext("2d");
                            canvas.width = w;
                            canvas.height = h;
                            ctx.drawImage(img, 0, 0, w, h);    //从指定位置裁剪原始图片指定宽高，填充到画布上：

                            var $preview = $('<li class="weui-uploader__file weui-uploader__file_status" style="background-image:url(' + img.src + ')"><div class="weui-uploader__file-content">0%</div></li>');
                            $('#uploaderFiles').append($preview);    //在指定元素中尾部插入内容

                            var num = $('.weui-uploader__file').length;     //获取li个数
                            currSelf.CurrImgNum = num;

                            //图片上传接口
                            var formData = new FormData();
                            formData.append("filetype", file.type);
                            formData.append("filename", file.name);
                            formData.append("files", file);
                            $.ajax({
                                url: "/jgmes/jgmesScrwAction!doFileUplod.action",
                                type: "post",
                                data: formData,
                                contentType: false,
                                processData: false,
                                success: function (result) {
                                    var data = JSON.parse(result);
                                    //console.log(data);
                                    if (data.IsSuccess) {
                                        var imgData = JSON.parse(data.Data);
                                       // console.log(imgData);
                                        $($preview)[0].setAttribute('data-id', imgData.id);     //setAttribute() 方法添加指定的属性，并为其赋指定的值。
                                        $($preview)[0].setAttribute('data-url', imgData.path);
                                        $preview.removeClass('weui-uploader__file_status');
                                        currSelf.ImagePaths.push(imgData);
                                        $.toast("上传成功", function () {
                                            //console.log('close');
                                        });
                                        //$(".weui-uploader__input-box").hide();
                                    }
                                },
                                error: function (xhr, type) {
                                    alert('Ajax error!')
                                }
                            });
                        }
                    }

                    //FileReader.onprogress在读取数据过程中周期性调用
                    reader.onprogress = function (e) {
                        var percentComplete = ((e.loaded / e.total) || 0) * 100;
                        //console.log(percentComplete);
                    }
                }
                $("#uploaderInput").val("");
            },

            //链接跳转到检验项目页面方法
            GoCheckoutProject:function(){
                var currSelf = this;
                if(!currSelf.FormData.MasterID || currSelf.FormData.MasterID == null){
                    $.toptip("请先选择检验方案","warning")
                }else {
                    window.location.href = "/JG/Quality/MobileCheckoutProject.html?MasterID=" + currSelf.FormData.MasterID;
                }
            },

            //保存按钮方法
            SaveBtn:function() {
                var currSelf = this;
                var msg;
                currSelf.InspectionList = [];     //清空之前检验项目表数据
                currSelf.FormData.YesOrNotCheckout = "";   //清空之前选中的合格或不合格
                currSelf.FormData.YesOrNotCheckout = $(".choice_btn").find("input[type=radio]:checked").val();   //是否合格名称


                //子表数据的集合
                // var ClassDivNames= document.getElementsByClassName('radio_div');
                // for(var i=0;i<ClassDivNames.length;i++){
                //     var DivElement=ClassDivNames[i];
                //     currSelf.InspectionList.push({
                //         "SJJYZB_JYXMBM":$(DivElement).find(".p_coding").text(),    //检验项目编码
                //         "SJJYZB_NO_CODE":$(DivElement).find(".p_code").text(),   //是否检验值，布尔值
                //         "SJJYZB_HG_NAME":$(DivElement).find(".p_checkout>input[type=radio]:checked").val(),   //是否合格名称
                //         "SJJYZB_CKZ":$(DivElement).find(".p_reference").text(),   //参考值
                //         "SJJYZB_JYZ":$(DivElement).find(".p_value>input").val(),   //检验值
                //         //"SJJYZB_JYZ":currSelf.FormData.TextValue,   //检验值
                //     });
                // }
                //
                // $.each(currSelf.InspectionList,function(i,item){
                //     //console.log(i);
                //     // console.log(item);
                //     console.log(currSelf.InspectionList[i]);
                // });

                if (!currSelf.FormData.NowProductionLineCode || currSelf.FormData.NowProductionLineCode == null) {
                    msg = '请先选择产线！';
                    $.toptip(msg, "warning");
                } else if (!currSelf.FormData.InspectName || currSelf.FormData.InspectName == null) {
                    msg = '还没填写送检人姓名!';
                    $.toptip(msg, "warning");
                } else if (currSelf.LoginUser == null) {
                    msg = '没有检验人姓名!';
                    $.toptip(msg, "warning");
                }
                // else if (!currSelf.TaskCodeGat || currSelf.TaskCodeGat.length) {
                //     msg = '请先选择任务单相关信息!';
                //     $.toptip(msg, "warning");
                // }
                else if (!currSelf.FormData.MasterID || currSelf.FormData.MasterID == null) {
                    msg = '该产线下的任务单没有相关检验方案，请重新选择任务单信息!';
                    $.toptip(msg, "warning");
                } else if(!currSelf.FormData.YesOrNotCheckout){
                    msg = '请先选择检验结果!';
                    $.toptip(msg, "warning");
                }else {
                    $.confirm("确定为不合格吗？", "操作提示", function () {
                        //主表数据集合
                        var jsonStr = JSON.stringify({
                            "SJJY_RWDH": currSelf.FormData.TaskCode,     //任务单号
                            "SJJY_DDH": currSelf.FormData.OrderCode,      //订单号
                            "SJJY_CPBM": currSelf.FormData.InvCode,     //产品编码
                            "JGMES_ZLGL_SJJY_ID": currSelf.FormData.MasterID,    //检验标准主表 ID
                            "SJJY_CXBM": currSelf.FormData.NowProductionLineCode,      //当前产线编码
                            "SJJY_NO_NAME": currSelf.FormData.YesOrNotCheckout,        //是否合格名称
                            "SJJY_SJR": currSelf.FormData.InspectName,       //送检人
                            "SJJY_JYR": currSelf.LoginUser,       //检验人
                        });

                        //var jsonStrDetail = currSelf.InspectionList;

                        //批量保存数据接口
                        $.showLoading();
                        $.ajax({
                            type: "post",
                            //async: false,
                            url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!doSaveFirstInspection.action",
                            data: {
                                "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                "mac": LocalUserInfo.GetUserInfo().Mac,
                                "jsonStr": jsonStr,       //主表
                                //"jsonStrDetail": "",     //子表
                            },
                            dataType: "json",
                            success: function (result) {
                                var retData = ReturnData(result);
                                if (retData.IsSuccess) {
                                    msg = "保存成功!";
                                    $.toptip(msg, "success");
                                } else {
                                    msg = "保存失败!";
                                    $.toptip(msg, "error");
                                }
                            },
                            error: function (xhr, status, errorThrow) {
                                console.error(status);
                                //$.alert("批量保存数据失败！");
                            },
                            complete: function () {
                                $.hideLoading();
                            }
                        });
                    });
                }
            }
        },
    });
</script>
</html>